/*
 * YuebaoDownloadTaskManager.h
 *
 *  Created on: 2011-3-11
 *      Author: 
 */

#ifndef YuebaoDownloadTaskManager_H_
#define YuebaoDownloadTaskManager_H_
#include <e32base.h>
#include <e32cmn.h>
#include "Downloader.h"

class YuebaoDownloadTask;
class YuebaoFramework;
class YuebaoDownloadTaskManager;
class YuebaoDownloadTaskManagerObserver
{
public:
    virtual void TaskRemoved( YuebaoDownloadTaskManager*, int index ) = 0;
};

class XmlWriter;

class YuebaoDownloadTaskManager : public CBase, public HttpDownloadEngineObserver
{
public:
    YuebaoDownloadTaskManager( YuebaoFramework* framework );
    ~YuebaoDownloadTaskManager( );
public:
    void ConstructL( );
public:
    RPointerArray< YuebaoDownloadTask > _un_purchased;
public:
    bool IsExist( int id );
    bool AddTask( int id, const TDesC& name, const TDesC& url );
    void AddTask( YuebaoDownloadTask* goods );
public:
    void Save( );
    void Load( );
public:
    void StartTask( )
    {
        StartNextTask( -1, true );
    }
public:
    void StartTaskAt( int index );
    void StopTaskAt( int index );
    void WaitingTaskAt( int index );
    void RemoveTaskAt( int index );
protected:
    int TaskIndex( int id );
protected:
    void StartNextTask( int index, bool startDownloading );
public:
    YuebaoFramework* _framework;
protected:
    HttpDownloadEngine* _downloader;
protected:
    void HttpDownloadEvent( TInt aEventCode, int total, int downloaded );
    char* HttpDownloadEngineObserverID( )
    {
        return "YuebaoDownloadTaskManager";
    }
public:
    YuebaoDownloadTaskManagerObserver* _observer;
private:
    XmlWriter* _writer;
    HBufC* _buffer;
};

#endif /* YUEBAOPUSRCHESDATA_H_ */
